-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI auth #699
UI auth #699
Conversation
redirect for when password is incorrect, saying something like “invalid password, redirect to the login page”
|
40d6bf1
to
2fd13f4
Compare
2fd13f4
to
321cb75
Compare
68a2268
to
88f7bda
Compare
There are some UI refinements for a later PR, but this is looking good for now. LGTM! |
|
||
import { NextResponse } from 'next/server'; | ||
|
||
export default function middleware(req: NextRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of something like:
const router = createEdgeRouter<NextRequest, NextFetchEvent>();
router.use('/', async (request) => {
let path = request.nextUrl.pathname;
let excludedPaths = ['/api/auth/callback', '/api/auth/login'];
if (!excludedPaths.includes(path)) {
// ...
return authMiddleware(request);
} else {
return NextResponse.next();
}
});
export function middleware(request: NextRequest, event: NextFetchEvent) {
return router.run(request, event);
}
export const config = {
matcher: [
// Match everything other than static assets
'/((?!_next/static|_next/image|favicon.ico).*)',
],
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add export const config
but for now the rest seems unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left one comment for your consideration, but overall good
82a3cff
to
82d0f87
Compare
Implement the most primitive authentication scheme I could think of
Extending this can be done in future by introducing new supporting environment variables
If someone feels queasy about storing password in cookie, a 2nd env variable can be made,
PEERDB_PASSWORD_TOKEN
, which the cookie is set to instead of the passwordOn cloud we'll want to use
pbkdf2
or some other key derivation function so that we never store the password anywhere. So add aPEERDB_PASSWORD_FUNCTION
variable & setPEERDB_PASSWORD
to{algo:'SHA512',iter:999999,salt:'random',auth:'result'}
& have login handler hash password accordingly. Managed service would handle setting these environment variables on customer's setup